//
//  StatusCellBottomView.swift
//  sinaDemo
//
//  Created by mac on 15/12/18.
//  Copyright © 2015年 zhouxubin. All rights reserved.
//

import UIKit
import SnapKit

class StatusCellBottomView: UIView {
    
    @objc private func clickCommentButton() {
        respondViewController()?.pushViewController(TestViewController(), animated: true)
    }
    
    // 分割线的缩放比例
    let lineScale = 0.4
    
    // MARK: 懒加载子控件
    // 转发按钮
    private var reweetButton: UIButton = UIButton(image: "timeline_icon_retweet", backImage: nil, title: "转发", color: UIColor.grayColor(), fontSize: 13)
    
    // 评论按钮
    private var commentButton: UIButton = UIButton(image: "timeline_icon_comment", backImage: nil, title: "评论", color: UIColor.grayColor(), fontSize: 13)
    
    // 点赞按钮
    private var likeButton: UIButton = UIButton(image: "timeline_icon_unlike", backImage: nil, title: "赞", color: UIColor.grayColor(), fontSize: 13)
    
    // 分割线
    private var leftImage: UIImageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line_highlighted"))
    
    private var rightImage: UIImageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line_highlighted"))
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        // 初始化子控件
        setUpSubViews()
    }
    
    // 初始化子控件
    private func setUpSubViews() {
        addSubview(reweetButton)
        addSubview(commentButton)
        addSubview(likeButton)
        addSubview(leftImage)
        addSubview(rightImage)
        
        // 添加评论按钮的点击事件
        commentButton.addTarget(self, action: "clickCommentButton", forControlEvents: UIControlEvents.TouchUpInside)
    }
    
    // 设置按钮的约束
    override func layoutSubviews() {
        super.layoutSubviews()
        // 转发按钮
        reweetButton.snp_makeConstraints { (make) -> Void in
            make.left.top.bottom.equalTo(self)
            make.width.equalTo(likeButton.snp_width)
        }
        
        // 点赞按钮
        likeButton.snp_makeConstraints { (make) -> Void in
            make.top.right.bottom.equalTo(self)
            make.width.equalTo(commentButton.snp_width)
        }

        // 评论按钮
        commentButton.snp_makeConstraints { (make) -> Void in
            make.top.bottom.equalTo(self)
            make.left.equalTo(reweetButton.snp_right)
            make.right.equalTo(likeButton.snp_left)
        }
        
        // 左边分割线
        leftImage.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(reweetButton.snp_right)
            make.centerY.equalTo(self.snp_centerY)
            make.height.equalTo(self.snp_height).multipliedBy(lineScale)
        }
        
        // 右边分割线
        rightImage.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(commentButton.snp_right)
            make.centerY.equalTo(self.snp_centerY)
            make.height.equalTo(self.snp_height).multipliedBy(lineScale)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
